<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>找回密码</title>
    <script src="__JS__/jquery.js"></script>
    <link href="__CSS__/boot.css" rel="stylesheet">
    <link href="__STATIC__/layui/css/layui.css" rel="stylesheet">
    <script src="__JS__/layer/layer.js"></script>
    <script src="__STATIC__/layui/layui.js"></script>
</head>
<body>
<div style="height: 100px;"></div>
<div style="width: 500px;height:400px;margin: 0 auto;border: 1px solid #dddddd;" >
    <div >
        <div style="width: 200px;float: left;font-size: 25px">
            修改密码
        </div>
        <div style="width:70px;float: right">
            <button type="button" id="login" class="btn btn-link">返回登录</button>
        </div>
    </div>
    <div style="height: 80px;"></div>
    <div style="width: 550px;margin-left: 40px;">
        <label style="display: none;color: red;text-align: center" id="info"></label>
        <form class="layui-form" action="" id="myform">
            <input type="hidden" name="token" value="{$token}">
            <div class="layui-form-item">
                <label class="layui-form-label" style="width: 100px">新密码:</label>
                <div class="layui-input-block">
                    <input type="password" style="width: 300px" onblur="verificationpass()" placeholder="新密码由6-20位字母，数字，下划线组成" name="pass" required  lay-verify="required"  autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label" style="width: 100px">确认密码:</label>
                <div class="layui-input-block">
                    <input type="password" style="width: 300px" onblur="verificationpassword()" name="password" required  lay-verify="required"  autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button type="button" id="update" class="btn btn-primary" style="width: 200px">修改</button>
                </div>
            </div>
        </form>
    </div>
</div>

</body>
<script>
    //返回登录
    $("#login").click(function () {
        window.location.href = "{:url('business/login/index')}";
    });
    //验证密码
    function verificationpass() {
        var password = $("input[name=pass]").val();
        var patrn =/^(\w){6,20}$/;
        if(!password){
            $("#info").html('请输入密码');
            $("#info").css('display','block');
            return ;
        }
        if(!patrn.test(password)){
            $("#info").html('密码格式不正确');
            $("#info").css('display','block');
            return ;
        }
        $("#info").css('display','none');
    }
    //确认密码
    function verificationpassword() {
        var patrn =/^(\w){6,20}$/;
        var password = $("input[name=password]").val();
        var pass = $("input[name=pass]").val();
        if(pass != password){
            $("#info").html('两次密码不一致');
            $("#info").css('display','block');
            return ;
        }else{
            $("#info").css('display','none');
        }
        if(!patrn.test(pass)){
            $("#info").html('密码格式不正确');
            $("#info").css('display','block');
            return ;
        }
    }
    //修改密码
    $("#update").click(function () {
        var pass = $("input[name=pass]").val();
        var password = $("input[name=password]").val();
        if(!pass){
            layer.alert('请输入密码');
            return;
        }
        if(!password){
            layer.alert('请输入确认密码');
            return;
        }
        $.ajax({
            url:"{:url('business/forget/updatepassword')}",
            data:$("#myform").serialize(),
            type:"post",
            dataType:"json",
            success:function (res) {
                if(res.success){
                    layer.alert(res.success,function () {
                        window.location.href = "{:url('business/login/index')}";
                    },function () {
                        window.location.href = "{:url('business/login/index')}";
                    });
                }
                if(res.error){
                    layer.alert(res.error);
                }
            }
        });
    });
</script>
</html>